package it.intecs.pisa.smarcos.activities;

import it.intecs.pisa.smarcos.R;
import it.intecs.pisa.smarcos.base.SpeechManager;
import android.app.Activity;
import android.os.Bundle;
import android.os.Vibrator;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;

 
public class Confirmation extends Activity implements OnTouchListener    {
	
	public static final String INTENT_SHOW="it.intecs.pisa.smarcos.activities.Confirmation.SHOW";
	private static final String TAG = Confirmation.class.getSimpleName();
	private static final long CLICK_SPEED = 250; // TODO Add in the user preference
	
	private SpeechManager speechManager;
	private Vibrator vibrator;
	View view; 
	LayoutInflater inflater;
	protected int curX,curY;
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		Log.d(TAG, "OnCreate");
		speechManager = SpeechManager.getInstance(getApplicationContext());
		vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
	
		setContentView(R.layout.confirmation);
		view = (ViewGroup) findViewById(R.id.closebutton);
			
		view.setOnTouchListener(this);
	}
	
	@Override
	public void onResume() {
		super.onResume();

		speechManager.say(R.string.TTS_WIFI_CONFIRMATION);
	}

	@Override
	public void onPause() {
		super.onPause();
		Log.d(TAG, "OnPause");	

	}

	public boolean onTouch(View v, MotionEvent event) {
		
		Log.d(TAG, "onTouch");
		
		curX= (int) event.getX();
		curY= (int) event.getY();
		
		switch(event.getAction()) {
		
			case MotionEvent.ACTION_DOWN:
			
				speechManager.say(R.string.TTS_WIFI_CONFIRMATION);
				
			break;
			
			//case MotionEvent.ACTION_MOVE:
			//
			//	break;
			
			case MotionEvent.ACTION_UP:

				if ((event.getEventTime() - event.getDownTime()) < CLICK_SPEED) {
					speechManager.say(getString(R.string.TTS_WIFI_CONFIRMATION), true, true);
					vibrator.vibrate(200);
					finish(); 
				}
			break;
		}
	
		return true;
	}
	
}


